package cn.yunhe.dao;

import cn.yunhe.pojo.*;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public interface HouseDao {

    House searchHouse(int hid);

    List<House> houseList();
    List<House> houseList(House house);

    boolean insertHouse(House house);
    boolean updateHouse(House house);
    boolean deleteHouse(House house);

    public static final
    RowMapper houseRowMapper=new ParameterizedRowMapper<House>() {
        @Override
        public House mapRow(ResultSet rs, int rowNum) throws SQLException {
            House house=new House();
            house.setHid(rs.getInt("hid"));
            house.setHtitle(rs.getString("htitle"));
            house.setHprice(rs.getDouble("hprice"));
            house.setHfloorage(rs.getDouble("hfloorage"));
            house.setHpubdate(rs.getString("hpubdate"));
            house.setHcontact(rs.getString("hcontact"));
            house.setHdesc(rs.getString("hdesc"));
            house.setHflag(rs.getInt("hflag"));
            Member member=new Member();
            member.setMid(rs.getInt("mid"));
            member.setMname(rs.getString("mname"));
            Type type=new Type();
            type.setTid(rs.getInt("tid"));
            type.setTname(rs.getString("tname"));
            Street street=new Street();
            street.setSid(rs.getInt("sid"));
            street.setSname(rs.getString("sname"));
            District district=new District();
            district.setDid(rs.getInt("did"));
            district.setDname(rs.getString("dname"));
            street.setDistrict(district);

            house.setMember(member);
            house.setType(type);
            house.setStreet(street);
            return house;
        }
    };



}
